All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JRootPane

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.JRootPane

public class JRootPane
extends JComponent
implements Accessible
The fundamental component in the container hierarchy. In the same way that JComponent is fundamental to the JFC/Swing components, JRootPane is fundamental to the JFC/Swing window, frame, and pane containers. However, while other classes use inheritance to take advantage of JComponent's capabilities, the container classes delegate operations to a JRootPane instance. Those containers are the heavyweight containers: JFrame, JDialog, JWindow, and JApplet, as well as the lightweight container, JInternalFrame.

The following image shows these relationships:

The "heavyweight" components (those that delegate to a peer, or native component on the host system) are shown with a darker, heavier box. The four heavyweight JFC/Swing containers (JFrame, JDialog, JWindow, and JApplet) are shown in relation to the AWT classes they extend. These four components are the only heavyweight containers in the Swing library. The lightweight container, JInternalPane, is also shown. All 5 of these JFC/Swing containers implement the RootPaneContainer interface, and they all delegate their operations to a JRootPane (shown with a little "handle" on top).
Note: The JComponent method getRootPane can be used to obtain the JRootPane that contains a given component.
The diagram at right shows the structure of a JRootPane. A JRootpane is made up of a glassPane, an optional menuBar, and a contentPane. (The JLayeredPane manages the menuBar and the contentPane.) The glassPane sits over the top of everything, where it is in a position to intercept mouse movements. Since the glassPane (like the contentPane) can be an arbitrary component, it is also possible to set up the glassPane for drawing. Lines and images on the glassPane can then range over the frames underneath without being limited by their boundaries.

Although the menuBar component is optional, the layeredPane, contentPane, and glassPane always exist. Attempting to set them to null generates an exception.

The contentPane must be the parent of any children of the JRootPane. Rather than adding directly to a JRootPane, like this:

       rootPane.add(child);
 
You instead add to the contentPane of the JRootPane, like this:
       rootPane.getContentPane().add(child);
 
The same priniciple holds true for setting layout managers, removing components, listing children, etc. All these methods are invoked on the contentPane instead of on the JRootPane.
Note: The default layout manager for the contentPane is a BorderLayout manager. However, the JRootPane uses a custom LayoutManager. So, when you want to change the layout manager for the components you added to a JRootPane, be sure to use code like this:
    rootPane.getContentPane().setLayout(new BoxLayout());
 
If a JMenuBar component is set on the JRootPane, it is positioned along the upper edge of the frame. The contentPane is adjusted in location and size to fill the remaining area. (The JMenuBar and the contentPane are added to the layeredPane component at the JLayeredPane.FRAME_CONTENT_LAYER layer.)

The layeredPane is the parent of all children in the JRootPane. It is an instance of JLayeredPane, which provides the ability to add components at several layers. This capability is very useful when working with menu popups, dialog boxes, and dragging -- situations in which you need to place a component on top of all other components in the pane.

The glassPane sits on top of all other components in the JRootPane. That provides a convenient place to draw above all other components, and makes it possible to intercept mouse events, which is useful both for dragging and for drawing. Developers can use setVisible on the glassPane to control when the glassPane displays over the other children. By default the glassPane is not visible.

The custom LayoutManager used by JRootPane ensures that:

  1. The glassPane, if present, fills the entire viewable area of the JRootPane (bounds - insets).
  2. The layeredPane fills the entire viewable area of the JRootPane. (bounds - insets)
  3. The menuBar is positioned at the upper edge of the layeredPane().
  4. The contentPane fills the entire viewable area, minus the MenuBar, if present.
Any other views in the JRootPane view hierarchy are ignored.

If you replace the LayoutManager of the JRootPane, you are responsible for managing all of these views. So ordinarily you will want to be sure that you change the layout manager for the contentPane rather than for the JRootPane itself!

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
JLayeredPane, JMenuBar, JWindow, JFrame, JDialog, JApplet, JInternalFrame, JComponent, BoxLayout,

Variable Index

 o contentPane
The content pane.
 o defaultButton
The button that gets activated when the pane has the focus and a UI-specific action like pressing the Enter key occurs.
 o defaultPressAction
The action to take when the defaultButton is pressed.
 o defaultReleaseAction
The action to take when the defaultButton is released.
 o glassPane
The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such.
 o layeredPane
The layered pane that manages the menu bar and content pane.
 o menuBar
The menu bar.

Constructor Index

 o JRootPane()
Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane.

Method Index

 o addImpl(Component, Object, int)
Overridden to enforce the position of the glass component as the zero child.
 o addNotify()
Register ourselves with the SystemEventQueueUtils as a new root pane.
 o createContentPane()
Called by the constructor methods to create the default contentPane.
 o createGlassPane()
Called by the constructor methods to create the default glassPane.
 o createLayeredPane()
Called by the constructor methods to create the default layeredPane.
 o createRootLayout()
Called by the constructor methods to create the default layoutManager.
 o getAccessibleContext()
Get the AccessibleContext associated with this JComponent
 o getContentPane()
Returns the content pane -- the container that holds the components parented by the root pane.
 o getDefaultButton()
Returns the current default button for this JRootPane.
 o getGlassPane()
Returns the current glass pane for this JRootPane.
 o getJMenuBar()
Returns the menu bar from the layered pane.
 o getLayeredPane()
Get the layered pane used by the root pane.
 o getMenuBar()
Deprecated.
 o isValidateRoot()
If a descendant of this JRootPane calls revalidate, validate from here on down.
 o removeNotify()
Unregister ourselves from SystemEventQueueUtils.
 o setContentPane(Container)
Sets the content pane -- the container that holds the components parented by the root pane.
 o setDefaultButton(JButton)
Sets the current default button for this JRootPane.
 o setGlassPane(Component)
Sets a specified Component to be the glass pane for this root pane.
 o setJMenuBar(JMenuBar)
Adds or changes the menu bar used in the layered pane.
 o setLayeredPane(JLayeredPane)
Set the layered pane for the root pane.
 o setMenuBar(JMenuBar)
Deprecated.

Variables

 o menuBar
 protected JMenuBar menuBar
The menu bar.

 o contentPane
 protected Container contentPane
The content pane.

 o layeredPane
 protected JLayeredPane layeredPane
The layered pane that manages the menu bar and content pane.

 o glassPane
 protected Component glassPane
The glass pane that overlays the menu bar and content pane, so it can intercept mouse movements and such.

 o defaultButton
 protected JButton defaultButton
The button that gets activated when the pane has the focus and a UI-specific action like pressing the Enter key occurs.

 o defaultPressAction
 protected JRootPane. DefaultAction defaultPressAction
The action to take when the defaultButton is pressed.

See Also:
defaultButton
 o defaultReleaseAction
 protected JRootPane. DefaultAction defaultReleaseAction
The action to take when the defaultButton is released.

See Also:
defaultButton

Constructors

 o JRootPane
 public JRootPane()
Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane.

Methods

 o createLayeredPane
 protected JLayeredPane createLayeredPane()
Called by the constructor methods to create the default layeredPane. Bt default it creates a new JLayeredPane.

 o createContentPane
 protected Container createContentPane()
Called by the constructor methods to create the default contentPane. By default this method creates a new JComponent add sets a BorderLayout as its LayoutManager.

 o createGlassPane
 protected Component createGlassPane()
Called by the constructor methods to create the default glassPane. By default this method creates a new JComponent with visibility set to false.

 o createRootLayout
 protected LayoutManager createRootLayout()
Called by the constructor methods to create the default layoutManager.

 o setJMenuBar
 public void setJMenuBar(JMenuBar menu)
Adds or changes the menu bar used in the layered pane.

Parameters:
menu - the JMenuBar to add
 o setMenuBar
 public void setMenuBar(JMenuBar menu)
Note: setMenuBar() is deprecated. As of Swing version 1.0.3 replaced by setJMenuBar(JMenuBar menu).

 o getJMenuBar
 public JMenuBar getJMenuBar()
Returns the menu bar from the layered pane.

Returns:
the JMenuBar used in the pane
 o getMenuBar
 public JMenuBar getMenuBar()
Note: getMenuBar() is deprecated. As of Swing version 1.0.3 replaced by getJMenubar().

 o setContentPane
 public void setContentPane(Container content)
Sets the content pane -- the container that holds the components parented by the root pane.

Parameters:
content - the Container to use for component-contents
Throws: IllegalComponentStateException
(a runtime exception) if the content pane parameter is null
 o getContentPane
 public Container getContentPane()
Returns the content pane -- the container that holds the components parented by the root pane.

Returns:
the Container that holds the component-contents
 o setLayeredPane
 public void setLayeredPane(JLayeredPane layered)
Set the layered pane for the root pane. The layered pane typically holds a content pane and an optional JMenuBar.

Parameters:
layered - the JLayeredPane to use.
Throws: IllegalComponentStateException
(a runtime exception) if the layered pane parameter is null
 o getLayeredPane
 public JLayeredPane getLayeredPane()
Get the layered pane used by the root pane. The layered pane typically holds a content pane and an optional JMenuBar.

Returns:
the JLayeredPane currently in use
 o setGlassPane
 public void setGlassPane(Component glass)
Sets a specified Component to be the glass pane for this root pane. The glass pane should normally be a lightweight, transparent component, because it will be made visible when ever the root pane needs to grab input events. For example, only one JInternalFrame is ever active when using a DefaultDesktop, and any inactive JInternalFrames' glass panes are made visible so that clicking anywhere within an inactive JInternalFrame can activate it.

Parameters:
glass - the Component to use as the glass pane for this JRootPane.
 o getGlassPane
 public Component getGlassPane()
Returns the current glass pane for this JRootPane.

Returns:
the current glass pane.
See Also:
setGlassPane
 o isValidateRoot
 public boolean isValidateRoot()
If a descendant of this JRootPane calls revalidate, validate from here on down.

Deferred requests to relayout a component and it's descendants, i.e. calls to revalidate(), are pushed upwards to either a JRootPane or a JScrollPane because both classes override isValidateRoot() to return true.

Returns:
true
Overrides:
isValidateRoot in class JComponent
See Also:
isValidateRoot
 o addNotify
 public void addNotify()
Register ourselves with the SystemEventQueueUtils as a new root pane.

Overrides:
addNotify in class JComponent
See Also:
addRunnableCanvas
 o removeNotify
 public void removeNotify()
Unregister ourselves from SystemEventQueueUtils.

Overrides:
removeNotify in class JComponent
See Also:
removeRunnableCanvas
 o setDefaultButton
 public void setDefaultButton(JButton defaultButton)
Sets the current default button for this JRootPane. The default button is the button which will be activated when a UI-defined activation event (typically the key) occurs in the RootPane regardless of whether or not the button has keyboard focus (unless there is another component within the RootPane which consumes the activation event, such as a JTextPane). For default activation to work, the button must be an enabled descendent of the RootPane when activation occurs. To remove a default button from this RootPane, set this property to null.

Parameters:
default - the JButton which is to be the default button
See Also:
isDefaultButton
 o getDefaultButton
 public JButton getDefaultButton()
Returns the current default button for this JRootPane.

Returns:
the JButton which is currently the default button
 o addImpl
 protected void addImpl(Component comp,
                        Object constraints,
                        int index)
Overridden to enforce the position of the glass component as the zero child.

Overrides:
addImpl in class Container
 o getAccessibleContext
 public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent

Returns:
the AccessibleContext of this JComponent
Overrides:
getAccessibleContext in class JComponent

All Packages  Class Hierarchy  This Package  Previous  Next  Index